//
//  ALPEditorCell.m
//  AlpFM
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 Alp. All rights reserved.
//

#import "ALPEditorCell.h"
#import "ALPEditorCollectionViewCell.h"
#import "ALPEditorPlayVC.h"
#import "ALPEditorDetailModel.h"
#import "ALPAppTools.h"
@interface ALPEditorCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, strong) UICollectionView *myCollection;
@property (nonatomic, strong)UILabel *title;      //小编推荐
@property (nonatomic, strong) UIImageView *sanjiao; //三角图标
@property (nonatomic, strong) UIImageView *xijiantou; //细箭头
@property (nonatomic, strong) UILabel *gengduo;  //更多
@property (nonatomic, strong) NSMutableArray *allArray;
@end

@implementation ALPEditorCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creat];
    }
    return self;
}

-(void)creat{
    self.sanjiao = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 16, 16)];
    self.sanjiao.image = [UIImage imageNamed:@"sanjiao"];
    [self.contentView addSubview:self.sanjiao];
    
    self.title = [[UILabel alloc]initWithFrame:CGRectMake(35, 9, 100, 20)];
    self.title.font = [UIFont boldSystemFontOfSize:16];
    self.title.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.title];
    
    self.gengduo = [[UILabel alloc]initWithFrame:CGRectMake(325, 9, 30, 20)];
    self.gengduo.text = @"更多";
    self.gengduo.textColor = [UIColor grayColor];
    self.gengduo.font = [UIFont boldSystemFontOfSize:14];
    [self.contentView addSubview:self.gengduo];
    
    self.xijiantou = [[UIImageView alloc]initWithFrame:CGRectMake(355, 9, 15, 15)];
    self.xijiantou.image = [UIImage imageNamed:@"xijiantou"];
    [self.contentView addSubview:self.xijiantou];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(325, 0, 50, 40);
    [button addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:button];
    
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(111.7, 180);
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    flowLayout.minimumLineSpacing = 10;  //列间隙
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.myCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 30, 375, 170) collectionViewLayout:flowLayout];
    self.myCollection.delegate = self;
    self.myCollection.dataSource = self;
    self.myCollection.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myCollection];
    [self.myCollection registerClass:[ALPEditorCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.allArray = [NSMutableArray array];
    
    NSString *strUrl = @"http://mobile.ximalaya.com/mobile/discovery/v1/recommend/editor?device=android&pageId=1&pageSize=20&title=更多";
    [ALPAppTools getWithAFNurl:strUrl block:^(id result) {
        NSMutableArray *array = [result objectForKey:@"list"];
        for (NSMutableDictionary *dic in array) {
            ALPEditorDetailModel *model = [[ALPEditorDetailModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:model];
        }
        [self.myCollection reloadData];
    } error:^(NSError *error) {
        
        
    }];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ALPEditorCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.threeModel = _mol.list[indexPath.row];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ALPEditorDetailModel *mol = [self.allArray objectAtIndex:indexPath.row];
    [self.xieyiren sendIndPath:indexPath.row + 1 idid:mol.albumId jishu:mol.tracksCounts];
 
}

 //  相当于请求数据
-(void)setMol:(ALPSecondEditorModel *)mol{
    _mol = mol;
    self.title.text = _mol.title;
    self.array = [NSMutableArray arrayWithArray:_mol.list];
    [self.myCollection reloadData];
}



-(void)push:(UIButton *)btn{
    [self.xieyiren jumpToDetail:_mol.title];
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
